package main

import (
	"fmt"
	"net/http"
)

func main() {
	resp, err := http.Get("http://127.0.0.1:8000/1.txt")
	if err != nil {
		fmt.Println("http get err:", err)
		return
	}
	defer resp.Body.Close()
	//简单查看应答包
	fmt.Println("Header:", resp.Header)
	fmt.Println("Status:", resp.Status)

	buf := make([]byte, 4096)
	var str string
	for {
		n, _ := resp.Body.Read(buf)
		if n == 0 { //在网络和channel中用n==0来判断文件结尾
			fmt.Printf("Read finish")
			break
			// } else if err != nil {//本地文件中用EOF来判断文件结尾
			// 	fmt.Println("----error:", err)
			// 	break
		}
		str += string(buf[:n])

	}
	fmt.Printf("|%v|\n", str)
}
